package com.lllmark.lllmarkDemo.mapper;

import com.lllmark.lllmarkDemo.entity.dto.UserDTO;
import com.lllmark.lllmarkDemo.entity.po.User;
import com.lllmark.lllmarkDemo.entity.vo.UserVO;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;

/**
 * @author yuxiangZhang
 * @data 2024/5/11
 */
@Mapper
public interface UserMapper {
    /**
     * 查询单个用户
     * @param id
     * @return
     */
    @Select("select id, user_name, avatar, gender, age from user where id = #{id}")
    UserVO selectById(Integer id);

    /**
     * 分页查询
     * @return
     */
    @Select("select user_id, user_name, avatar, gender, age from user limit #{page}, #{pageSize}")
    List<UserVO> selectAll(UserDTO userDTO);

    @Select("select count(id) from user")
    Integer getUserCounts();



    /**
     * 新增用户
     * @param user
     * @return
     */
    @Insert("insert into `user` value(null, #{userId}, #{userName}, #{avatar}," +
            " #{gender}, #{age}, #{joinTime}, #{updateTime})")
    Integer insert(User user);

    /**
     * 批量/删除用户
     * @param id
     * @return
     */
    @Delete("delete from user where id = #{id}")
    Integer delete(Integer id);

    /**
     * 修改用户信息
     * @param userDTO
     * @return
     */
    @Update("update user set user_name = #{userName}, gender = #{gender}, age = #{age} where id = #{id}")
    Integer update(UserDTO userDTO);






}
